package Repositorio;

import java.security.interfaces.RSAKey;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import Classes.Disciplina;
import GUI.CadAluno;
import Repositorio.ConexaoDB;

import javax.swing.JOptionPane;


public class Rep_Disciplina extends ConexaoDB {
	
	public void InserirDisciplinaDB(Disciplina disciplina){
		
		if (AbrirCon())
		{
			String sql = "";
			
			sql = 	"insert into DISCIPLINA (NOME,CARGA_HORARIA, DESCRICAO_EMENTA, ID_PROFESSOR)"
					 + " values ('"+disciplina.getNome()+"','"+disciplina.getCarga_horaria()+"','"
					 +disciplina.getDescricao_ementa()+"','"+disciplina.getId_professor()+"')";
		
			System.out.println(sql);

			try 
			{
				stmt = con.createStatement();
				executeUptade(sql);
			
				JOptionPane.showMessageDialog(null, "Disciplina Cadastrada com Sucesso.");	
				sql = null;
			}
			catch (Exception e) 
			{
				JOptionPane.showMessageDialog(null, e.toString(), "erro", 0);
				sql = null;
			}
			finally
			{
				FecharCon();
				System.out.println("Conexao Encerrada com o Banco!");
			
			}
			}
	}
	
	public ArrayList ListarProfessor() 
	{
		List<String> strList = new ArrayList<String>();  
		
		if (AbrirCon())
		{
			//Statement st = null;
			String sql = "";

			try 
			{

				sql = "select nome from professor";

				ResultSet rs = executeQuery(sql);

				while (rs.next()) 
				{
					strList.add(rs.getString("nome"));
				} 
				return (ArrayList) strList;
				}
				catch (Exception e) 
				{
					e.printStackTrace();
					return null;
				}
				finally
				{
					FecharCon();
					System.out.println("Conexao Encerrada com o Banco!");
				}
		}
		return null;

	}
	
	public int PegaIDProf(String nome_prof)
	{
		if (AbrirCon())
		{
			String sql = "";
		
			try
			{
				sql = 	"select cod_prof "+
						"from professor "+
						"where nome = '"+ nome_prof+"'";

				return executeQuery(sql).getInt("cod_prof");

			}
			catch (Exception e)
			{
				e.printStackTrace();
				return (Integer) null;
			}
			finally
			{
				FecharCon();
				System.out.println("Conexao Encerrada com o Banco!");
			}
			
		}
		return 0;
	
	
	}

}
